package com.hzit;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import com.baomidou.mybatisplus.generator.fill.Column;

import javax.swing.*;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public class MpGenerator {
	public static void main(String[] args) {
		String url = "jdbc:mysql://localhost:3306/513yuke?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai";
		String username = "root";
		String password = "123456";
		FastAutoGenerator.create(url, username, password)

				.globalConfig((scanner, builder) -> builder.author(scanner.apply("请输入作者名称？"))
						.outputDir(scanner.apply("请输入输出路径？"))
				)


				.strategyConfig((scanner, builder) -> builder
						.addInclude(getTables(scanner.apply("请输入表名，多个英文逗号分隔？所有输入 all")))
						.addTablePrefix("tb_")  
						.entityBuilder()
						.enableLombok()

						.addTableFills(
								new Column("create_time", FieldFill.INSERT)
						)
						.build())
				.templateEngine(new FreemarkerTemplateEngine())
				.execute();
	}

	protected static List<String> getTables(String tables) {
		return "all".equals(tables) ? Collections.emptyList() : Arrays.asList(tables.split(","));
	}
}


